package com.chukun.concurrency.singleton;

import com.chukun.concurrency.annotations.ThreadSafe;

/**
 * 使用枚举模式创建单例对象,不会有线程安全的问题
 */
@ThreadSafe
public class SingletonBuilder5 {

    private SingletonBuilder5(){}

    private static SingletonBuilder5 getInstance(){
        return  SingleTonBuilderHolder.INSTANCE.getInstance();
    }

    /**
     * 使用枚举实现单例模式
     */
    public enum  SingleTonBuilderHolder{
        INSTANCE;

        private  SingletonBuilder5 instance;

        SingleTonBuilderHolder(){
            instance = new SingletonBuilder5();
        }

        private   SingletonBuilder5 getInstance(){
            return instance;
        }
    }


}
